//
//  WHRRobOrderListCell.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/12/11.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "WHRRobOrderListCell.h"
#import "UIView+SDAutoLayout.h"
#import "UIView+SDAutoLayout.h"
#import "SDWeiXinPhotoContainerView.h"


@implementation WHRRobOrderListCell

{
    UIImageView *_iconView;
    UILabel *_nameLable;
    UILabel *_priceLabel;
    UILabel *_contentLabel;
    SDWeiXinPhotoContainerView *_picContainerView;
    UILabel *_timeLabel;
    UIButton *_shopBtn;
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
    }
    return self;
}

- (void)setup
{
    _iconView = [UIImageView new];
    
    _nameLable = [UILabel new];
    _nameLable.font = [UIFont systemFontOfSize:14];
    _nameLable.textColor = [UIColor colorWithRed:(54 / 255.0) green:(71 / 255.0) blue:(121 / 255.0) alpha:0.9];
    
    
    _priceLabel = [UILabel new];
    _priceLabel.textColor = COLOR_ORG;
    _priceLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_priceLabel];
    
    _contentLabel = [UILabel new];
    _contentLabel.font = [UIFont systemFontOfSize:15];
    
    _picContainerView = [SDWeiXinPhotoContainerView new];
    
    _timeLabel = [UILabel new];
    _timeLabel.font = [UIFont systemFontOfSize:13];
    _timeLabel.textColor = [UIColor lightGrayColor];
    
    _shopBtn = [[UIButton alloc]init];
    _shopBtn.titleLabel.font = FONT_FOURTEEN;
    _shopBtn.backgroundColor = COLOR_ORG;
    [_shopBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_shopBtn setTitle:@"立即抢单" forState:UIControlStateNormal];
    [self.contentView addSubview:_shopBtn];
    
    
    
    NSArray *views = @[_iconView, _nameLable, _contentLabel, _picContainerView, _timeLabel];
    
    [views enumerateObjectsUsingBlock:^(UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self.contentView addSubview:obj];
    }];
    
    UIView *contentView = self.contentView;
    CGFloat margin = 10;
    
    _iconView.sd_layout
    .leftSpaceToView(contentView, margin)
    .topSpaceToView(contentView, margin + 5)
    .widthIs(40)
    .heightIs(40);
    
    _nameLable.sd_layout
    .leftSpaceToView(_iconView, margin)
    .topEqualToView(_iconView)
    .heightIs(18);
    [_nameLable setSingleLineAutoResizeWithMaxWidth:200];
    
    
    _priceLabel.sd_layout
    .rightSpaceToView(self.contentView, 10)
    .topEqualToView(_nameLable)
    .widthIs(100)
    .heightRatioToView(_nameLable, 1);
    
    
    _contentLabel.sd_layout
    .leftEqualToView(_nameLable)
    .topSpaceToView(_nameLable, margin)
    .rightSpaceToView(contentView, margin)
    .autoHeightRatio(0);
    
    _picContainerView.sd_layout
    .leftEqualToView(_contentLabel);
    
    _timeLabel.sd_layout
    .leftEqualToView(_contentLabel)
    .topSpaceToView(_picContainerView, margin)
    .widthIs(200)
    .heightIs(20);
    
    _shopBtn.sd_layout
    .rightSpaceToView(self.contentView, 30)
    .topSpaceToView(_timeLabel, margin)
    .widthIs(100)
    .heightIs(40);
    
   
    
    [self setupAutoHeightWithBottomView:_shopBtn bottomMargin:margin + 5];
    
}



- (void)setModel:(WHRRobOrderListModel *)model {
    
    _model = model;
    [_iconView sd_setImageWithURL:[NSURL URLWithString:_model.fProfilePhoto] placeholderImage:[UIImage imageNamed:@"placeHold"]];
    _nameLable.text = [NSString stringWithFormat:@"用户名:%@",_model.fNickname];
    _contentLabel.text = [NSString stringWithFormat:@"问题描述:%@",_model.fSymptomInfo];
    _priceLabel.text = [NSString stringWithFormat:@"价格:%@",_model.fPrice];
    
    
    NSArray *urlAry = [_model.fUpImg componentsSeparatedByString:@","];
    NSMutableArray *imageUrlAry = [NSMutableArray array];
    [urlAry enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *imageUrl = [NSString stringWithFormat:@"%@%@", @"https://tzhg-pic.oss-cn-beijing.aliyuncs.com/", obj];
        [imageUrlAry addObject:imageUrl];
    }];
    
    /** 给数组赋值 */
    model.picNamesArray = imageUrlAry;
    _picContainerView.picPathStringsArray = model.picNamesArray;
    CGFloat picContainerTopMargin = 0;
    if (model.picNamesArray.count) {
        picContainerTopMargin = 10;
    }
    _picContainerView.sd_layout.topSpaceToView(_contentLabel, picContainerTopMargin);
    _timeLabel.text = _model.fCreateTime;
  
    
  
    
    
}


@end
